<?php

	// TITLE: Committee AUTO MODEL
	// FILE: scaffolding/model/committee.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createCommittee = function($con, $committee) {
		$sql = 'INSERT INTO committee (id, title, description) VALUES (';
		$sql .= $committee->getId() . ', ';
		$sql .= $committee->getTitle() . ', ';
		$sql .= $committee->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readCommittee = function($con, $id) {
		$sql = 'SELECT * FROM committee WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$committee = new Committee();
			$committee->setId(result[0]);
			$committee->setTitle(result[1]);
			$committee->setDescription(result[2]);
		} else {
			$committee = false;
		}
		return $committee;
	};

	$updateCommittee = function($con, $committee) {
		$sql = 'UPDATE committee SET ';
		$sql .= 'id = ' . $committee->getId() . ', ';
		$sql .= 'title = ' . $committee->getTitle() . ', ';
		$sql .= 'description = ' . $committee->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteCommittee = function($con, $id) {
		$sql = 'DELETE FROM committee WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listCommittee = function($con) {
		$sql = 'SELECT * FROM committee';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$committees = array();
			while ($result = mysqli_fetch_array($results)) {
				$committee = new Committee();
				$committee->setId(result[0]);
				$committee->setTitle(result[1]);
				$committee->setDescription(result[2]);
				$committees[] = committee;
			}// end while
		} else {
			$committees = false;
		}
		return $committees;
	};

